package weaver.ihg.schedule;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import weaver.conn.RecordSet;
import weaver.interfaces.schedule.BaseCronJob;


/**
 * 任务待发清单 每日校验刷新
 * 删除 智能布署任务清单 表
 * 草稿&&未发送
 * 修改
 */
public class Sync_TaskDelete extends BaseCronJob {

    private final Logger logger = LoggerFactory.getLogger(Sync_TaskDelete.class);


    @Override
    public void execute() {

        logger.info("Sync_TaskDelete_start____");
        RecordSet taskSelRS = new RecordSet();
        String taskSelSql = "select * from  uf_znbsqd where  sfyfs = 1"; //是否已发送 1=未发送  2=已合并
        logger.info("Sync_TaskDelete_taskSelSql:"+taskSelSql);
        taskSelRS.executeQuery(taskSelSql);
        while (taskSelRS.next()) {

            String id = taskSelRS.getString("id");  //致胜指数
            String sfyfs = taskSelRS.getString("sfyfs");  //发送状态  已发= 0  未发=1
            String gfxzsxx  = taskSelRS.getString("gfxzsxx");  //高风险指数信息表id(可能是多个)
            String sfcg  = taskSelRS.getString("sfcg");  //是否草稿

            if ("0".equals(sfcg)){
                continue;  //当是草稿时，则不进行删除
            }

            logger.info("Sync_TaskDelete_Id:"+id+"  "+"_gfxzsxx:"+gfxzsxx +" _sfyfs:"+sfyfs);
            RecordSet taskDeleteSet = new RecordSet();
            if ("1".equals(sfyfs)){
                if (!"".equals(gfxzsxx)){
                    String update = "update uf_gfxzsxxgl set sfyscdfqd = 1 where id in ( "+gfxzsxx+")";
                    taskDeleteSet.executeUpdate(update);
                    logger.info("Sync_TaskDelete_update:"+update);
                }else {
                    logger.info("Sync_TaskDelete_update:gfxzsxx is null");
                }
            }

            //删除 待发清单
            String taskDeleteSql = "DELETE FROM uf_znbsqd where id = "+id;
            taskDeleteSet.execute(taskDeleteSql);
            logger.info("Sync_TaskDelete_taskDeleteSql:"+taskDeleteSql);

            //删除待发清单明细表1
            String taskDtDeleteSql = "DELETE FROM uf_znbsqd_dt1 where mainid = "+id;
            taskDeleteSet.execute(taskDtDeleteSql);
            logger.info("Sync_TaskDelete_taskDtDeleteSql_dt1:"+taskDtDeleteSql);
            //删除待发清单明细表2
            taskDtDeleteSql = "DELETE FROM uf_znbsqd_dt2 where mainid = "+id;
            taskDeleteSet.execute(taskDtDeleteSql);
            logger.info("Sync_TaskDelete_taskDtDeleteSql_dt2:"+taskDtDeleteSql);

        }
    }
}
